package com.zb.jnlxc.aop;

import org.springframework.util.StopWatch;

/**
 * Created by zhengbo on 15/12/7.
 */
public class StopWatchUtil {
    static ThreadLocal<StopWatch> stopWatchThreadLocal = new ThreadLocal<StopWatch>();
    public static void startWatch(){
        StopWatch stopWatch = new StopWatch();
        stopWatch.start();
        stopWatchThreadLocal.set(stopWatch);
    }

    public static long getTotalTime(){
        StopWatch stopWatch = stopWatchThreadLocal.get();
        if(stopWatch!=null){
            stopWatch.stop();
            long time = stopWatch.getTotalTimeMillis();
            stopWatchThreadLocal.remove();
            return time;
        }else {
            return 0;
        }
    }
}
